Programming a Word Game

by Janet Terra

janetterra@yahoo.com

Home

Using QCard DLL - Lesson 3 - Watson

Sprite Byte - Watson

Programming a Word Game - Terra

Maven Puzzle Contest - Terra

Adding an Icon to the Taskbar - Lewis

Beginning Programming IX - Moore

Rendering Solid Objects - Nally


Submission Guildlines

Newsletter Help

Index

Whether it's a classic ScrabbleTM game or a similar game (BoggleTM, Text TwistTM, Anagram, Lexicon), word games can be a fun way to show off and increase your vocabulary. At least two word games are available for Liberty BASIC: [Boogle] originated by Tom Watson (later modified to search a word list and renamed [Boggle Game] by David Drake) and [CryptoPuzzle] by David Drake.

Some word games (e.g., CryptoPuzzle) have pre-determined, programmer coded words that the user must identify. The words in a themed lexicon word game may also be preprogrammed. More often, though, word games are dependent upon computer-generated words by sequencing letters in some order (e.g., BoggleTM) and thus require a resource to check the validity of those words.

Word Lists and Dictionaries

A word list is exactly that - a list of words. A dictionary is a list of words with a definition accompanying each word. For most games, a word list is sufficient, but where are you going to get this word list? Unless you feel up to creating your own list of words, you're going to want to find a ready-made word list to create valid words. A [Google]TM search yielded two public domain Word Lists available for download:

Word Lists Released into Public Domain

[ENABLE2K] - Originally released in 1997 and updated in 2000, The Enhanced North American Benchmark Lexicon has become a "recognized standard and benchmark" (from the ENABLE readme.txt file) for the serious ScrabbleTM player. This list of 173,528 has been in the Public Domain since its release. The author is Mendel Cooper with help from Alan Beale. The ENABLE packet comes complete with documentation and utility files (written in C+) for modifying the list.

[YAWL] - Yet Another Word List is authored by the same [Mendel Cooper and Alan Beale]. Why, you might ask, would they release a second word list to public domain when they had already released ENABLE? The YAWL list contains 264,057 words (all words in the ENABLE list plus several later supplements) and the authors consider this list to be the "most comprehensive" ScrabbleTM list ever comprised. This download packets contains a simple anagram game and a multianagram game, both written in C+.

[Official 12Dicts Package] is a collection of 12 English word lists. The packet contains 6 word list files and 3 documentation files. This list is oriented toward more common, less obscure words than ENABLE2K or YAWL. The programmer using this packet, though, will either have to search the 6 separate files or combine the files into one with duplicates removed. The 12Dicts Package was compiled and released into the Public Domain by Alan Beale (sans Mr. Cooper).

What is Public Domain?

As defined on the Project Gutenberg website, "Creating the works from public domain print editions means that no one owns a United States copyright in these works, so the [Gutenberg] Foundation (and you!) can copy and distribute it in the United States without permission and without paying copyright royalties." Literary works placed in the public domain become the property of the public. Thus, the public, as a group or as an individual, can do with that work whatever that group or individual wishes. Material once placed in the public domain, may be freely "reproduced, distributed, transmitted, used, modified, built upon, or otherwise exploited by anyone for any purpose, commercial or non-commercial, and in any way, including by methods that have not yet been invented or conceived."

Free to Use But Non-Public Domain Word Lists

Similar to open source, non-public domain word lists are available for no fee or royalty. With these 'free to use but not to own' lists, the author retains ownership of the list. That can sometimes be an advantage, as the author continues to assume responsibility for the veracity, maintenance and updating of the word list. One such word list is offered by [Justin White]. Justin's license clearly states that the word list is free to be used and/or modified, but Justin requests a credit and/or acknowledgement.

Dictionary and Thesaurus

The only downloadable public-domain dictionary I found was [OPTED] (Online Plain Text English Dictionary) based upon the 1913 Miriam Webster Dictionary and made available through the efforts of [Project Guttenbert] . Likewise, Project Gutenberg has also made available the 1911 version of [Roget's Thesaurus of English Words and Phrases]. While some entries may be non-existent in these works (you'll find aeroplane but not airplane and don't even think about cyberspace), most common words are readily found. The structure of Roget's Thesaurus is based upon classification and chapter rather than list and thus is not conducive or amenable to the needs of a word game.

Word List or Dictionary?

The dictionary makes a nice resource but cannot take the place of a word list as not all variations of the same word make the list. For example, simple plurals and singular verbs ending in -s are not listed separately. Using a dictionary, the computer will pick up kite but not kites, kick but not kicks. At the other end of the spectrum, the word list is designed to be comprehensive and will often contain obscure words that will be difficult to find in any unabridged dictionary. The dilemma is that a dictionary is not enough and a word list may be too much.

Searching the Word List or Dictionary

Once a word list (and supporting dictionary file if desired) is found, the game can begin. Searching a sequential file is fairly easy. Most often, items in a sequential file are retrieved one item at a time

 Input #1, txt$

or one line at a time

 Line Input #1, txt$ 

If using a dictionary, it would probably be best to use Line Input and a very large array. To retrieve all the words in a text file and store those words in a single variable use the method employed by David Drake in his enhanced [Boggle] game.

Open "wordlist.txt" for Input as #1
   wordlist$ = Input$(#1,LOF(#1))
Close #1

Keep this word list, but then make a second string variable of all extracted words with the desired starting length (e.g., 6 letters). From this second string, use the Rnd and Word$ functions to choose one word as the starting word. The next phase is to permutate (get all variations of the scrambled letters) the word. The following is based upon the [recursive permutation function] written by Norman in response to a [contest challenge] issued by Brad Moore. This modification is posted here with Norman's permission. Note the variable nPerms must first be stated as a global variable. This precludes use of this function in Liberty BASIC versions prior to 4.0.

    Function permutation$(pre$, post$)
        lgth = Len(post$)
        If lgth < 2 Then
            nPerms = nPerms + 1
            anagram$(nPerms) = pre$;post$
        Else
            For i = 1 To lgth
                tmp$=permutation$(pre$+Mid$(post$,i,1),Left$(post$,i-1)+Right$(post$,lgth-i))
            Next i
        End If
    End Function

Once permutated, the array entries are edited for duplication and validity. Now the game begins. Use the Instr function, (again thanks to David Drake for this tip in his Boggle Game) to compare the user's entry with your newly compiled list of valid words. A barebones demo of a single player anagram game using Justin White's word list can be found in the archive files of this newsletter. It does take several minutes for the computer to read and search the text files. If you are interested in pursuing word games, you might consider rewriting the one large text file into several smaller files identified by the starting letter of the word. This will greatly speed up the search of an individual word.

What's Next?

A truly interactive BoggleTM-type game? A word search game? A crossword puzzle dictionary where the user enters the number of letters and any known letters? Perhaps a foreign language word translator. Who knows what can be done with a good word list and a searchable dictionary!


Home

Using QCard DLL - Lesson 3 - Watson

Sprite Byte - Watson

Programming a Word Game - Terra

Maven Puzzle Contest - Terra

Adding an Icon to the Taskbar - Lewis

Beginning Programming IX - Moore

Rendering Solid Objects - Nally


Submission Guildlines

Newsletter Help

Index